package com.marketlive.system.config;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/

import org.marketlive.system.config.IConfigurationContext;

import java.util.Locale;

/**
 * 
 * Specifies the root of a tree comprised of <code>IConfigurationBranch</code>es and 
 * <code>IConfigurationLeaf</code>s. 
 * @author Huw
 *
 */
public class ConfigurationContext implements IConfigurationContext {

    private String client;
    private String environment;
    private String host;
    private String vmId;
    private String vmType;


    /**
     * Logger
     */
    private static Log log = LogFactory.getLog(ConfigurationContext.class);

    /**
     * @inheritDoc
     */
    public String getClient() {
        return client;
    }

    /**
     * Sets the name of the context client.
     * 
     * @param client the name to set
     */
    public void setClient(String client) {
        this.client = client;
    }


    /**
     * @inheritDoc
     */
    public String getEnvironment() {
        return environment;
    }

    /**
     * Sets the environment for this context.
     * 
     * @param environment the environment to set
     */
    public void setEnvironment(String environment) {
        this.environment = environment;
    }

    /**
     * @inheritDoc
     */
    public String getHost() {
        return host;
    }

    /**
     * Sets the host name for the VM this context is running under.
     * 
     * @param host the name to set
     */
    public void setHost(String host) {
        this.host = host;
    }

    /**
     * @inheritDoc
     */
    public String getVmId() {
        /*
        String id = System.getProperty(JVM_ID_KEY);
        if (id==null || id=="") {
            id = JVM_ID_DEFAULT;
        }
        return id;
        */
        return vmId;
    }

    /**
     * Sets the ID of this VM.
     * 
     * @param vmId the ID to set
     */
    public void setVmId(String vmId) {
        this.vmId = vmId;
    }

    /**
     * @inheritDoc
     */
    public String getVmType() {
        /*
        String type = System.getProperty(JVM_TYPE_KEY);
        if (type==null || type=="") {
            type = JVM_TYPE_DEFAULT;
        }
        return type;
        */
        return vmType;
    }

    /**
     * Sets the type of VM this context is running under.
     * 
     * @param vmType the type of VM to set
     */
    public void setVmType(String vmType) {
        this.vmType = vmType;
    }

    /**
     * @inheritDoc
     */
    public Locale getLocale() {
        return Locale.getDefault();
    }
    
    /**
     * Returns this context as a string for display.
     * @return this context as a string
     */
    public String toString() {
    	StringBuffer out = new StringBuffer(1000);
    	ConfigurationToString.toStringBuilder(out, this, 0);
    	return out.toString();
}
}
